﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Twi.COMMON.WCF
{
    public static class ExceptionExtensions
    {
        public static string GetFullMessage(this Exception ex) 
        {           
            if (GetCustomFullMessage != null)
            {
                return GetCustomFullMessage(ex);
            }

            StringBuilder sb = new StringBuilder("服务器端异常");
            sb.AppendLine();
            sb.AppendLine("------------------------------------");
            sb.AppendLine(ex.Message);
            sb.AppendLine("------------------------------------");
            sb.AppendLine(ex.StackTrace);

            //if (ex.InnerException != null)
            //{
            //    sb.AppendLine(ex.InnerException.Message);
            //    if (ex.InnerException.InnerException != null)
            //    {
            //        sb.AppendLine(ex.InnerException.InnerException.Message);
            //    }
            //}
            return sb.ToString();
        }

        public static Func<Exception, string> GetCustomFullMessage;
    }
}
